package org.peterf.foxish.component.updater;

import org.peterf.foxish.component.property.Updatable;
import org.peterf.foxish.component.updater.interfaces.Gradual;

public class QuadraticLineUpdater implements Gradual {

    private float a;
    
    private float b;
    
    private float c;
    
    private float x0;
    
    private float x1;
    
    private float progress = 0.0f;
    
    public QuadraticLineUpdater(float a, float b, float c, float x0, float x1) {
        this.a = a;
        this.b = b;
        this.c = c;
        this.x0 = x0;
        this.x1 = x1;
    }
    
    public boolean isFinished() {
        return progress >= 1.0f;
    }

    public void reset() {
        progress = 0.0f;
    }

    public void update(Updatable updatable, float elapsed) {
        float x = x0 * (1.0f - progress) + x1 * progress;
        float y = a * x * x + b * x + c;
        updatable.getMatrix().postTranslate(x, y);
    }

    public float getProgress() {
        return progress;
    }

    public void setProgress(float progress) {
        this.progress = progress;
    }

}
